package logger

import (
	"io"
	"os"
	"path"

	"github.com/sirupsen/logrus"
	"gopkg.in/natefinch/lumberjack.v2"
)

var (
	log    = logrus.New()
	Debug  = log.Debug
	Debugf = log.Debugf
	Info   = log.Info
	Infof  = log.Infof
	Warn   = log.Warn
	Warnf  = log.Warnf
	Error  = log.Error
	Errorf = log.Errorf
)

func Setting(logPath string) {
	log.Formatter = &logrus.TextFormatter{
		FullTimestamp:   true,
		TimestampFormat: "2006-01-02 15:04:05",
	}

	log.Out = io.MultiWriter(os.Stdout, &lumberjack.Logger{
		Filename:   path.Join(logPath),
		MaxSize:    10, // 日志文件最大大小，单位：MB
		MaxBackups: 30, // 日志文件最多个数
		LocalTime:  true,
	})
}
